﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ProductMonitor.UserControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProductMonitor
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window 
    
    {
        public MainWindow()
        {
            InitializeComponent();

         
            //ix: 设置视频源为本地文件路径
            mediaElement.MediaEnded += (sender, e) =>
            {
                mediaElement.Position = TimeSpan.Zero; // 重置到视频开头
                mediaElement.Play();                  // 重新播放
            };
            mediaElement.Play(); // 初始启动播放
        }

        public void ShowDetailPage()
        {
            WorkShopDetailUC workShopDetailUC = new WorkShopDetailUC(); // 创建工作车间详细信息用户控件实例[6,8](@ref)

            //动画效果
            ThicknessAnimation animation = new ThicknessAnimation
            {
                From = new Thickness(0, 0, -MainContent.ActualWidth, 0), // 从左侧外部开始[6,8](@ref)
                To = new Thickness(0), // 到达正常位置[6,8](@ref)
                Duration = TimeSpan.FromSeconds(0.5), // 动画持续时间[6,8](@ref)
                EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } // 缓动函数[6,8](@ref)
            };

            DoubleAnimation opacityAnimation = new DoubleAnimation(0 ,1, new TimeSpan(0 ,0 ,0 ,0 ,4000));// 从0到1的透明度变化[6,8](@ref)
            Storyboard.SetTarget(animation, workShopDetailUC); // 设置目标为工作车间详细信息用户控件[6,8](@ref)
            Storyboard.SetTarget(opacityAnimation, workShopDetailUC); // 设置透明度动画目标[6,8](@ref)

            Storyboard.SetTargetProperty(animation, new PropertyPath("Margin")); // 设置动画属性为Margin[6,8](@ref)
            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity")); // 设置透明度动画属性[6,8](@ref)

            Storyboard storyboard = new Storyboard(); // 创建Storyboard实例[6,8](@ref)
            storyboard.Children.Add(animation); // 添加动画到Storyboard[6,8](@ref)
            storyboard.Children.Add(opacityAnimation); // 添加透明度动画到Storyboard[6,8](@ref)
            storyboard.Begin(); // 开始动画[6,8](@ref)
            // 切换到工作车间详细信息页面[6,8](@ref)
            MainContent.Content = workShopDetailUC;
        }

        private void MinButton_Click(object sender, RoutedEventArgs e)// 最小化按钮点击事件处理[6,8](@ref)
        {
            this.WindowState = WindowState.Minimized; // 最小化窗口[6,8](@ref)
        }

        private void MaxButton_Click(object sender, RoutedEventArgs e)// 最大化按钮点击事件处理[6,8](@ref)
        {
            if (this.WindowState == WindowState.Normal)// 判断当前窗口状态[6,8](@ref)
            {
                this.WindowState = WindowState.Maximized;// 最大化窗口
                                                         // 切换最大化按钮图标[6,8](@ref)
                MaxButton.Content = "❐"; // 切换为还原图标
                                         // 防止窗口覆盖任务栏[6](@ref)
                this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;// 设置最大高度为屏幕高度
                this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;// 设置最大宽度为屏幕宽度
            }
            else
            {
                this.WindowState = WindowState.Normal;// 还原窗口
                MaxButton.Content = "□"; // 切换为最大化图标
            }
        }
        [RelayCommand]
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close(); // 关闭窗口[8,11](@ref)
        }
    }
}
